//
//  SEGActivityDetailViewModel.m
//  Commom
//
//  Created by Clavis on 2020/6/18.
//

#import "SEGActivityDetailViewModel.h"
#import <SEGModel/SEGActivityManager.h>

@interface SEGActivityDetailViewModel ()

@property (nonatomic, strong) SEGActivityManager *activityManager;
@property (nonatomic, assign) __block NSInteger commentPageIndex;
/// 活动评论总数
@property (nonatomic, copy, readwrite) NSString *commentsTotalCount;

@end

@implementation SEGActivityDetailViewModel

/// 加载活动详情信号量
- (RACSignal *)requestActicityDeatilSignal {
    if (!_requestActicityDeatilSignal) {
        @weakify(self);
        _requestActicityDeatilSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            [self.activityManager requestQueryActivityWithActId:self.actId finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                if (isSuccessed) {
                    // 第一次请求活动详情成功的时候 统计浏览
                    if (!self.isAreadyLoad) {
                        self.isAreadyLoad = YES;
                        [self.activityManager requestBrowseSharePraiseWithActId:self.actId actionType:@"1" finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                        }];
                        
                        // 如果是跳转福利社的触发类活动，则提前请求签到活动ID
                        if (self.activityManager.detailModel.actType.integerValue == SEGActivityType_Trigger && [self.activityManager.detailModel.triggerEvent isEqualToString:@"completeTask"]) {
                            [self.activityManager requestIsSignShow:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                                if (isSuccessed) {
                                    NSDictionary* dicData = [result valueForKey:@"data"];
                                    // 首页签到按钮活动ID
                                    NSString *homeSignActId = ValueToString(dicData[@"actId"]);
                                    self.homeSignActId = homeSignActId;
                                }
                            }];
                        }
                    }
                    [subscriber sendNext:self.activityManager.detailModel];
                    [subscriber sendCompleted];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _requestActicityDeatilSignal;
}

///// 加载评论信号量
//- (RACCommand *)requestCommentCommand {
//    if (!_requestCommentCommand) {
//        @weakify(self);
//        _requestCommentCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
//            @strongify(self);
//            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
//                if ([input boolValue]) {
//                    self.commentPageIndex = 1;
//                }
//                [self.activityManager requestActivityCommentsListByObjId:self.actId pageNo:self.commentPageIndex Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//                    if (isSuccessed) {
//                        //数据加载成功后加pageNo
//                        self.commentPageIndex ++;
//                        [subscriber sendNext:nil];
//                        [subscriber sendCompleted];
//                    }
//                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
//                    [subscriber sendError:error];
//                }];
//                return nil;
//            }];
//        }];
//    }
//    return _requestCommentCommand;
//}

/// 请求评论列表
/// @param isRefresh 是否刷新
- (RACSignal *)requestCommentList:(BOOL)isRefresh {
    return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        if (isRefresh) {
            self.commentPageIndex = 1;
        }
        [self.activityManager requestActivityCommentsListByObjId:self.actId pageNo:self.commentPageIndex Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if (isSuccessed) {
                //数据加载成功后加pageNo
                self.commentPageIndex ++;
                // 设置评论总数
                self.commentsTotalCount = ValueToString(result[@"data"][@"totalSize"]);
                [subscriber sendNext:nil];
                [subscriber sendCompleted];
            }
            NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
            [subscriber sendError:error];
        }];
        return nil;
    }];
}

/// 活动点赞信号量
- (RACSignal *)requestPraiseActivitySignal {
    if (!_requestPraiseActivitySignal) {
        @weakify(self);
        _requestPraiseActivitySignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            [self.activityManager requestBrowseSharePraiseWithActId:self.actId actionType:@"2" finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                @strongify(self);
                if(isSuccessed) {
                    [subscriber sendNext:self.activityManager.likeCount];
                    [subscriber sendCompleted];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _requestPraiseActivitySignal;
}


/// 对活动评论信号量
- (RACCommand *)submitCommnetCommand {
    if (!_submitCommnetCommand) {
        @weakify(self);
        _submitCommnetCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                // 数据处理
                NSString *content = [ValueToString(input) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
                if (content.length == 0) {
                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"请填写内容"}];
                    [subscriber sendError:error];
                    return nil;
                }
                if (content.length < 2) {
                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"输入内容不能少于2个字。"}];
                    [subscriber sendError:error];
                    return nil;
                }
                NSInteger maxLength = 140;
                if (content.length > maxLength) {
                    NSString *errorMessage = [NSString stringWithFormat:@"亲，您输入的内容已超过%ld字。", maxLength];
                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                    [subscriber sendError:error];
                    return nil;
                }
                
                @strongify(self);
                [self.activityManager requestCommentActivityWithObjId:self.actId quizContent:content quizPic:@"" show:@"1" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                    if (isSuccessed) {
                        [subscriber sendNext:nil];
                        [subscriber sendCompleted];
                    }
                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                    [subscriber sendError:error];
                }];

                
                return nil;
            }];
        }];
    }
    return _submitCommnetCommand;
}


/// 提交活动分享记录信号量
- (RACSignal *)submitShareRecordSignal {
    if (!_submitShareRecordSignal) {
        @weakify(self);
        _submitShareRecordSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            [self.activityManager requestBrowseSharePraiseWithActId:self.actId actionType:@"3" finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
            }];
            return nil;
        }];
    }
    return _submitShareRecordSignal;
}


/// 对评论点赞的信号量
- (RACCommand *)praiseCommentCommand {
    if (!_praiseCommentCommand) {
        @weakify(self);
        _praiseCommentCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            @strongify(self);
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                SEGActivityDetailCommentModel *commentModel = input;
                if ([commentModel.isParise isEqualToString:@"1"]) { // 已点赞，则取消点赞
                    [self.activityManager requestCancelPraiseByobjId:commentModel.quizId objType:@"2" Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                        if (isSuccessed) {
                            commentModel.isParise = @"0";
                            commentModel.praiseTotal = [NSString stringWithFormat:@"%d",[commentModel.praiseTotal intValue] - 1];
                            [subscriber sendNext:commentModel];
                            [subscriber sendCompleted];
                        }
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                        [subscriber sendError:error];
                    }];
                } else { // 未点赞，进行点赞
                    [self.activityManager requestPraiseAttentByObjId:commentModel.quizId
                                                             ObjType:@"2"
                                                     objPicUrlForMsg:commentModel.quizPic
                                                      objTitleForMsg:commentModel.quizContent
                                                      byReviewUserId:commentModel.userId
                                                         parentObjId:commentModel.quizId
                                                       parentObjType:@"6"
                                                       operationType:nil
                                                            Finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                        if (isSuccessed) {
                            commentModel.isParise = @"1";
                            commentModel.praiseTotal = [NSString stringWithFormat:@"%d",[commentModel.praiseTotal intValue] + 1];
                            [subscriber sendNext:commentModel];
                            [subscriber sendCompleted];
                        }
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                        [subscriber sendError:error];
                    }];

                }
                return nil;
            }];
        }];
    }
    _praiseCommentCommand.allowsConcurrentExecution = YES;
    return _praiseCommentCommand;
}
/// 检查活动是否审核
- (RACSignal *)checkActivityExamineSignal {
    if (!_checkActivityExamineSignal) {
        @weakify(self);
        _checkActivityExamineSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            [self.activityManager requestCheckActivityUnauditWithActId:self.actId finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                if (isSuccessed) {
                    [subscriber sendNext:nil];
                    [subscriber sendCompleted];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _checkActivityExamineSignal;
}

/// 请求抽奖活动主体
- (RACSignal *)requestLotteryDetailSignal {
    if (!_requestLotteryDetailSignal) {
        @weakify(self);
        _requestLotteryDetailSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            NSString *lotteryAct = self.isTriggerLottery ? @"2" : @"1";
            [self.activityManager requestLotteryByLotteryId:self.lotteryId.length > 0?self.lotteryId:self.activityManager.detailModel.actObj isLotteryAct:lotteryAct finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                if (isSuccessed) {
                    [subscriber sendNext:self.activityManager.lotteryDetailModel];
                    [subscriber sendCompleted];
                }else {
                    NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                    [subscriber sendError:error];
                }
            }];
            return nil;
        }];
    }
    return _requestLotteryDetailSignal;
}

/// 参与抽奖活动
- (RACSignal *)participateLotterySignal {
    if (!_participateLotterySignal) {
        @weakify(self);
        _participateLotterySignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            NSError *error = [self checkUserCanJoinActivity];
            if (error) {
                [subscriber sendError:error];
                return nil;
            }
            
            if ([self.activityManager.lotteryDetailModel.lotteryTimes integerValue] <= 0) {
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"亲，您今天的抽奖机会已经用完！明天再来试试吧！"}];
                [subscriber sendError:error];
                return nil;
            }
            
            [self.activityManager requestUserLotteryByActId:self.actId triggerEventId:@"0" lotteryId:self.activityManager.detailModel.actObj finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                if (isSuccessed) {
                    [subscriber sendNext:self.activityManager.lotteryResultModel];
                    [subscriber sendCompleted];
                    // 抽奖成功 触发行为积分
                    [[SEGAnalyseBehaviorManager sharedManager] requestIntegralGrowthWithCode:SEGIntegralCode.participateActivity module:SEGIntegralModule.activityDetail businessID:self.actId finished:nil];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            
            return nil;
        }];
    }
    return _participateLotterySignal;
}

/// 请求线下类 剩余名额和报名审核状态
- (RACSignal *)requestOfflineStatusSignal {
    if (!_requestOfflineStatusSignal) {
        @weakify(self);
        _requestOfflineStatusSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            [self.activityManager requestQueryOffLinePerCountByActId:self.actId actObj:self.activityManager.detailModel.actObj finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                if (isSuccessed) {
                    [subscriber sendNext:RACTuplePack(@(self.activityManager.applyAuditStatus), self.activityManager.offlineLiftCount)];
                    [subscriber sendCompleted];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _requestOfflineStatusSignal;
}

/// 参加线下活动
- (RACCommand *)joinOfflineActivityCommand {
    if (!_joinOfflineActivityCommand) {
        @weakify(self);
        _joinOfflineActivityCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            @strongify(self);
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                
                // 判断能否参加活动
                NSError *error = [self checkUserCanJoinActivity];
                if (error) {
                    [subscriber sendError:error];
                    return nil;
                }
                [subscriber sendNext:@""];
                // 检查活动是的审核
                [self.checkActivityExamineSignal subscribeNext:^(id  _Nullable x) {
                    // 参加活动数据异常处理
                    RACTupleUnpack(NSString *name, NSString *sex, NSString *tel, NSString *applyCount, NSString *remark) = input;
                    
                    // 姓名输入非空格判断
                    NSString *tempStr = [name stringByReplacingOccurrencesOfString:@" " withString:@""];
                    if (name.length == 0 || tempStr.length == 0) {
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"请输入您的姓名"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    if (tel.length == 0) {
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"请输入您的手机号码"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    if (tel.length != 11) {
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"您输入的手机号码有误，请重新输入"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    if (applyCount.length == 0) {
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"请输入报名人数"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    if (applyCount.integerValue <= 0) {
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"报名人数不少于1人"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    if (applyCount.integerValue > 999) {
                        [SEGAlertView showTmepMessageWithMessage:@""];
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"报名人数不超过999"}];
                        [subscriber sendError:error];
                        return;
                    }
                    
                    // 请求参加活动接口
                    [subscriber sendNext:@""];
                    [self.activityManager requestOffLineApplyByActId:self.actId actObj:self.activityManager.detailModel.actObj userName:name userSex:sex userTel:tel applyCount:applyCount remark:remark finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                       
                        if (isSuccessed) {
                            [subscriber sendNext:@""];
                            [subscriber sendCompleted];
                            
                            // 参加线下活动成功 触发行为积分
                            [[SEGAnalyseBehaviorManager sharedManager] requestIntegralGrowthWithCode:SEGIntegralCode.participateActivity module:SEGIntegralModule.activityDetail businessID:self.actId finished:nil];
                        }
                        NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                        [subscriber sendError:error];
                    }];
                    
                } error:^(NSError * _Nullable error) {
                    [subscriber sendError:error];
                }];
                return nil;
            }];
        }];
    }
    return _joinOfflineActivityCommand;
}

/// 参加触发活动
- (RACSignal *)joinTriggerActivitySignal {
    if (!_joinTriggerActivitySignal) {
        @weakify(self);
        _joinTriggerActivitySignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            // 判断能否参加活动
            NSError *error = [self checkUserCanJoinActivity];
            if (error) {
                [subscriber sendError:error];
                return nil;
            }
            // 检查活动审核状态
            [self.checkActivityExamineSignal subscribeNext:^(id  _Nullable x) {
                [subscriber sendNext:x];
                [subscriber sendCompleted];
            } error:^(NSError * _Nullable error) {
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _joinTriggerActivitySignal;
}


/// 参加征集活动
- (RACSignal *)joinCollectAvtivitySignal {
    if (!_joinCollectAvtivitySignal) {
        @weakify(self);
        _joinCollectAvtivitySignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            // 判断能否参加活动
            NSError *error = [self checkUserCanJoinActivity];
            if (error) {
                [subscriber sendError:error];
                return nil;
            }
            
            // 检查活动审核状态
            [self.checkActivityExamineSignal subscribeNext:^(id  _Nullable x) {
                // 检查活动是否上传过作品
                [self.activityManager requestCheckHasUploadedWithActId:self.actId finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                    [subscriber sendNext:RACTuplePack(@(self.activityManager.hasUploaded), errorMessage)];
                    [subscriber sendCompleted];
                }];
            } error:^(NSError * _Nullable error) {
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _joinCollectAvtivitySignal;
}


/// 触发抽奖Command
- (RACCommand *)triggerLotteryCommand {
    if (!_triggerLotteryCommand) {
        @weakify(self);
        _triggerLotteryCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            @strongify(self);
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                RACTupleUnpack(NSString *actid, NSString *triggerID, NSString *lotteryID) = input;
                [self.activityManager requestUserLotteryByActId:actid triggerEventId:triggerID lotteryId:lotteryID finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                    [subscriber sendNext:RACTuplePack(@(isSuccessed),errorMessage, self.activityManager.lotteryResultModel)];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _triggerLotteryCommand;
}


/// 检查用户是否能参加活动
- (NSError *)checkUserCanJoinActivity {
    // 数据异常
    if (!self.activityManager.detailModel) {
        return [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:kNetworkErrorMessage}];
    }
    
    //先判断活动是否在进行中
    if ([self.activityManager.detailModel.actStatus integerValue] == SEGActivityStatus_NotBegin) {
        return [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"亲！活动还未开始，请稍后再试哦！"}];
    }
    if ([self.activityManager.detailModel.actStatus integerValue] == SEGActivityStatus_Over) {
        return [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:@"亲，活动已结束，下次早点来吧！"}];
    }
    
    // 活动参与对象不包含未认证用户
    if (![self.activityManager.detailModel.joinObj containsObject:@"0"]) {
        SEGProfileModel *profile = [SEGProfileManager sharedManager].profile;
        
        SEGQueryauthinfoDataModel *data = [SEGQueryauthinfoManager sharedManager].QueryAuthInfo.data;
        if ([profile.type intValue] == kUserTypeZiLBuQ) {//未认证用户
            return [NSError errorWithDomain:NSURLErrorDomain code:kActicityErrorCode_NoAuth userInfo:@{NSLocalizedDescriptionKey:SEGBasicBussinessStringDefine.promptUserAuthentication}];
        }
    }
    
    return nil;
}

/// 提交事件
- (RACCommand *)submitEventCommand {
    if (!_submitEventCommand) {
        @weakify(self);
        _submitEventCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            @strongify(self);
            return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
                
                RACTupleUnpack(NSString* eventName, NSString*eventValue) = input;
                [self.activityManager requestSubmitEventWithEventName:eventName eventValue:eventValue finished:^(BOOL isSuccessed, id result, NSString* codeType, NSString* errorMessage) {
                    [subscriber sendNext:nil];
                    [subscriber sendCompleted];
                }];
                return nil;
            }];
        }];
    }
    return _submitEventCommand;
}

/// 检查签到气泡是否展示
- (RACSignal *)checkSignShowSignal {
    if (!_checkSignShowSignal) {
        @weakify(self);
        _checkSignShowSignal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            [self.activityManager requestIsSignShow:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                if (isSuccessed) {
                    NSDictionary* dicData = [result valueForKey:@"data"];
                    BOOL isHome = [ValueToString(dicData[@"isHome"]) isEqualToString:@"1"];//1:是,2:否
                    BOOL isSign = [ValueToString(dicData[@"isSign"]) isEqualToString:@"1"];//isSign  1:已签到 2：未签到
                    BOOL isShow = isHome & !isSign;
                    // 首页签到按钮活动ID
                    NSString *homeSignActId = ValueToString(dicData[@"actId"]);
                    [subscriber sendNext:RACTuplePack(homeSignActId, @(isShow))];
                    [subscriber sendCompleted];
                }
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:[codeType integerValue] userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }];
            return nil;
        }];
    }
    return _checkSignShowSignal;
}

#pragma mark - Getter
- (SEGActivityManager *)activityManager {
    if (!_activityManager) {
        _activityManager = [[SEGActivityManager alloc] init];
    }
    return _activityManager;
}

- (NSArray<SEGActivityDetailCommentModel *> *)commentsArray {
    return _activityManager.commentsArray;
}

@end
